<?php
$myDir = dirname(__FILE__) . "/";
require_once($myDir."../autoload.php");
if ( $argc == 1 || $argv[1] == "--help" ) {
  die( "\n\tUsage: php ".$argv[0]." [CONTROLLER_NAME] [FULL_PATH_TO_PROJECT]\n\n");  
}

$className = $argv[1];
$path      = $argv[2];

require_once($path . "user_autoload.php");
$contrConfig = Conf::get('controllerConfig');
if (array_key_exists($className, $contrConfig)) die("Controller ". $className . " already exists\n");


//generate controlelr file:
$contrTpl = file_get_contents($myDir. "controller.dry");
$contrCont = str_replace("__CLASS_NAME__", $className, $contrTpl);
file_put_contents($path. "controllers/".$className.".php", $contrCont);

//update controller config:
$conf = WebUtils::addControllerToConfig($className);
WebUtils::addClassToGenAutoload($className,$path,"controllers/");
file_put_contents(Conf::get('MY_HOME'). "config/web/controllers_config.php", $conf);

